# encoding: utf-8
class CulturalHeritage::CulturalHeritagePreRegister < ActiveRecord::Base
  has_attached_file:avatar
  belongs_to :obj_pre_register, :class_name => 'CulturalHeritage::PreRegisterRequest',  :foreign_key => 'pre_registers_request'
  has_many :list_parts, :class_name => 'CulturalHeritage::Part',  :foreign_key => 'cultural_heritage'
  has_many :list_cultural_heritages, :class_name => 'CulturalHeritage::CulturalHeritage',  :foreign_key => 'foundInId'
  has_many :list_avatars, :class_name => 'CulturalHeritage::CulturalHeritageAvatar',  :foreign_key => 'cultural_heritage'
  has_many :list_researches, :class_name => 'CulturalHeritage::CulturalHeritageFile',  :foreign_key => 'cultural_heritage'
  has_many :list_videos, :class_name => 'CulturalHeritage::CulturalHeritageYoutube',  :foreign_key => 'cultural_heritage'
  belongs_to :obj_collection, :class_name => 'CulturalHeritage::Collection',  :foreign_key => 'collection'
  belongs_to :obj_state, :class_name => 'CulturalHeritage::State',  :foreign_key => 'state'
  belongs_to :obj_group, :class_name => 'CulturalHeritage::Group',  :foreign_key => 'group'
  belongs_to :obj_subGroup, :class_name => 'CulturalHeritage::SubGroup',  :foreign_key => 'subGroup'
  belongs_to :obj_tipology, :class_name => 'CulturalHeritage::Tipology',  :foreign_key => 'tipology'
  #Revisar el caso de que sea mueble y esté en un inmueble o en una institucion cultural, implica polimorfismo
  #belongs_to :obj_located_at_cultural_heritage, :class_name => 'CulturalHeritage::CulturalHeritage',  :foreign_key => 'cultural_heritage'
  belongs_to :obj_period, :class_name => 'CulturalHeritage::Period',  :foreign_key => 'period'
  belongs_to :obj_culture, :class_name => 'CulturalHeritage::Culture',  :foreign_key => 'culture'
  belongs_to :obj_style, :class_name => 'CulturalHeritage::Style',  :foreign_key => 'style'
  belongs_to :obj_owner, :class_name => 'Security::Person',  :foreign_key => 'owner'
  belongs_to :obj_author, :class_name => 'Security::Person',  :foreign_key => 'author'
  belongs_to :obj_conservational_state, :class_name => 'CulturalHeritage::ConservationalState',  :foreign_key => 'conservationalState'
  belongs_to :obj_integrity_state, :class_name => 'CulturalHeritage::IntegrityState',  :foreign_key => 'integrityState'
  belongs_to :obj_shape, :class_name => 'CulturalHeritage::Shape',  :foreign_key => 'shape'
  belongs_to :obj_technique, :class_name => 'CulturalHeritage::Technique',  :foreign_key => 'technique'
  belongs_to :obj_topic, :class_name => 'CulturalHeritage::Topic',  :foreign_key => 'topic'
  belongs_to :obj_typeCulturalInstitution, :class_name => 'CulturalHeritage::TypeCulturalInstitution',  :foreign_key => 'typeCulturalInstitution'
  belongs_to :obj_culturalInstitution, :class_name => 'CulturalHeritage::CulturalInstitution',  :foreign_key => 'culturalInstitution'
  belongs_to :obj_cultural_heritage, :class_name => 'CulturalHeritage::CulturalHeritage',  :foreign_key => 'culturalInstitution'
  belongs_to :obj_found_in_cultural_heritage, :class_name => 'CulturalHeritage::CulturalHeritage',  :foreign_key => 'foundInId'


  def self.all_non_deleted
    return find(:all,:conditions=>{:deleted=>[0]},:select=>"cultural_heritage_cultural_heritages.materials,cultural_heritage_cultural_heritages.id,cultural_heritage_cultural_heritages.name,cultural_heritage_cultural_heritages.updated_at,cultural_heritage_cultural_heritages.nationalRegistrationCode,cultural_heritage_cultural_heritages.description,cultural_heritage_cultural_heritages.foundInId,cultural_heritage_cultural_heritages.height,cultural_heritage_cultural_heritages.long,cultural_heritage_cultural_heritages.width,cultural_heritage_cultural_heritages.weight,cultural_heritage_cultural_heritages.state,cultural_heritage_cultural_heritages.group,cultural_heritage_cultural_heritages.subGroup,cultural_heritage_cultural_heritages.tipology,cultural_heritage_cultural_heritages.typeCulturalInstitution,cultural_heritage_cultural_heritages.culturalInstitution,cultural_heritage_cultural_heritages.period,cultural_heritage_cultural_heritages.culture,cultural_heritage_cultural_heritages.style,cultural_heritage_cultural_heritages.owner,cultural_heritage_cultural_heritages.author,cultural_heritage_cultural_heritages.conservationalState,cultural_heritage_cultural_heritages.integrityState,cultural_heritage_cultural_heritages.shape,cultural_heritage_cultural_heritages.technique,cultural_heritage_cultural_heritages.topic")
  end

  def str_state
    if state.blank?
      return ""
    else
      obj_state = CulturalHeritage::State.find(state)
      return obj_state.name
    end
  end

  def str_group
    if group.blank?
      return ""
    else
      obj_group = CulturalHeritage::Group.find(group)
      return obj_group.name
    end
  end

  def str_subGroup
    if subGroup.blank?
      return ""
    else
      obj_subGroup = CulturalHeritage::SubGroup.find(subGroup)
      return obj_subGroup.name
    end
  end

  def str_tipology
    if tipology.blank?
      return ""
    else
      obj_tipology = CulturalHeritage::Tipology.find(tipology)
      return obj_tipology.name
    end
  end

  def str_typeCulturalInstitution
    if typeCulturalInstitution.blank?
      return ""
    else
      obj_typeCulturalInstitution = CulturalHeritage::TypeCulturalInstitution.find(typeCulturalInstitution)
      return obj_typeCulturalInstitution.name
    end
  end

  def str_culturalInstitution
    if culturalInstitution.blank?
      return ""
    else
      obj_culturalInstitution = CulturalHeritage::CulturalInstitution.find(culturalInstitution)
      return obj_culturalInstitution.name
    end
  end

  def str_period
    if period.blank?
      return ""
    else
      obj_period = CulturalHeritage::Period.find(period)
      return obj_period.name
    end
  end

  def str_culture
    if culture.blank?
      return ""
    else
      obj_culture = CulturalHeritage::Culture.find(culture)
      return obj_culture.name
    end
  end

  def str_style
    if style.blank?
      return ""
    else
      obj_style = CulturalHeritage::Style.find(style)
      return obj_style.name
    end
  end

  def str_owner
    if owner.blank?
      return ""
    else
      obj_person = Security::Person.find(owner)
      return obj_person.name
    end
  end

  def str_author
    if author.blank?
      return ""
    else
      obj_author = Security::Person.find(author)
      return obj_author.name
    end
  end

  def str_conservationalState
    if conservationalState.blank?
      return ""
    else
      obj_conservationalState = CulturalHeritage::ConservationalState.find(conservationalState)
      return obj_conservationalState.name
    end
  end

  def str_integrityState
    if integrityState.blank?
      return ""
    else
      obj_integrityState = CulturalHeritage::IntegrityState.find(integrityState)
      return obj_integrityState.name
    end
  end

  def str_shape
    if shape.blank?
      return ""
    else
      obj_shape = CulturalHeritage::Shape.find(shape)
      return obj_shape.name
    end
  end

  def str_technique
    if technique.blank?
      return ""
    else
      obj_technique = CulturalHeritage::Technique.find(technique)
      return obj_technique.name
    end
  end

  def str_topic
    if topic.blank?
      return ""
    else
      obj_topic = CulturalHeritage::Topic.find(topic)
      return obj_topic.name
    end
    
  end
end
